<?php

use App\AdminConfig;
function validateURL($URL)
{
    $pattern = "/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/";
    if (preg_match($pattern, $URL)) {
        return true;
    } else {
        return false;
    }
}

/**
 * @Desc: 获取配置值
 * @Author: woann <304550409@qq.com>
 * @param $key
 * @return array
 */
function getConfig($key)
{
    return AdminConfig::getValue($key);
}

function uuid()
{
    $chars = md5(uniqid(mt_rand(), true));
    $uuid = substr ( $chars, 0, 8 ) . '-'
        . substr ( $chars, 8, 4 ) . '-'
        . substr ( $chars, 12, 4 ) . '-'
        . substr ( $chars, 16, 4 ) . '-'
        . substr ( $chars, 20, 12 );
    return $uuid ;
}


/**
 * 生成签名
 *
 * @param String $url
 * @return string
 *
 */
function genSign($url)
{
    $time = time();
    $query = parse_url($url, PHP_URL_QUERY );

    $str = $query . "&time=" . $time;

    $sign = md5($str) . "&" . $time . "&" . uuid();


    if (!empty($query)) {
        return $url . "&sign=" . base64_encode($sign);
    }


    return $url . "?sign=" . base64_encode($sign);
}
